/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.edu.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.edu.entity.EduTalent;
import com.jeesite.modules.edu.service.EduTalentService;

/**
 * 人才称号Controller
 * @author 赵俊飞
 * @version 2019-03-02
 */
@Controller
@RequestMapping(value = "${adminPath}/edu/eduTalent")
public class EduTalentController extends BaseController {

	@Autowired
	private EduTalentService eduTalentService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public EduTalent get(String id, boolean isNewRecord) {
		return eduTalentService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("edu:eduTalent:view")
	@RequestMapping(value = {"list", ""})
	public String list(EduTalent eduTalent, Model model) {
		model.addAttribute("eduTalent", eduTalent);
		return "modules/edu/eduTalentList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("edu:eduTalent:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<EduTalent> listData(EduTalent eduTalent, HttpServletRequest request, HttpServletResponse response) {
		eduTalent.setPage(new Page<>(request, response));
		Page<EduTalent> page = eduTalentService.findPage(eduTalent);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("edu:eduTalent:view")
	@RequestMapping(value = "form")
	public String form(EduTalent eduTalent, Model model) {
		model.addAttribute("eduTalent", eduTalent);
		return "modules/edu/eduTalentForm";
	}

	/**
	 * 保存人才称号
	 */
	@RequiresPermissions("edu:eduTalent:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated EduTalent eduTalent) {
		eduTalentService.save(eduTalent);
		return renderResult(Global.TRUE, text("保存人才称号成功！"));
	}
	
	/**
	 * 删除人才称号
	 */
	@RequiresPermissions("edu:eduTalent:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(EduTalent eduTalent) {
		eduTalentService.delete(eduTalent);
		return renderResult(Global.TRUE, text("删除人才称号成功！"));
	}
	
}